create procedure wp_GetScript
	@state int
as
	declare @string varchar(max)
	declare @data varchar(max)
	declare @objectname varchar(max)
	declare @todrop bit

	if @state < 0
		select @todrop = 1
	else
		select @todrop = 0
	select @state = abs(@state)

	select @objectname = o.ObjectName
		from Objects o
		inner join Data d on d.ObjectID = o.ID
		where d.State = @state

	select @string = 'if exists(select 1 from sysobjects where id = object_id(' + @objectname + '))' + char(13) + char(10)
	select @string = @string + char(9) + 'drop procedure ' + @objectname + char(13) + char(10)

	if @todrop <> 1
	begin
		select @data = Data
			from Data
			where State = @state

		if isnull(@data, '') <> ''
		begin
			select @string = @string + 'go' + char(13) + char(10) + char(13) + char(10)
			select @string = @string + @data
		end
	end

	select @string